< previous page page_603 next page >

Page 603
transform both of these points. As long as you do not use any shape-deforming transformations like perspective projection, the normal vector between these two points is transformed correctly. When you need to use the normal vector, you can compute it by subtracting the two points.
The RayPlane class represents a plane. This class stores the coordinates of a point on the plane in the Point3D variable Point1. It stores the point that defines the normal vector in variable Point2. The following code shows the FindT function for the RayPlane class.
e10a6a0a59f035e870d90cca05b85fce.gif
' Return the value T for the point of intersection 
' between the vector from point (px, py, pz) in 
' the direction <vx, vy, vz>. 
'
' direct_calculation is true if we are finding the 
' intersection from a viewing position ray. It is 
' false if we are finding a reflected intersection 
' or a shadow feeler.
Public Function RayTraceable_FindT( _ 
    ByVal direct_calculation As Boolean, ByVal px As Single, _ 
    ByVal py As Single, ByVal pz As Single, _ 
    ByVal Vx As Single, ByVal Vy As Single, _ 
    ByVal Vz As Single) As Single 
Dim A As Single 
Dim B As Single 
Dim C As Single 
Dim D As Single 
Dim Nx As Single 
Dim Ny As Single 
Dim Nz As Single 
Dim denom As Single 
Dim t As Single 

    ' Do not cull planes. 

    ' Find the unit normal at this point. 
    GetUnitNormal Nx, Ny, Nz 

    ' Compute the plane's parameters. 
    A = Nx 
    B = Ny 
    C = Nz 
    D = -(Nx * Point1.Trans(1) + _ 
          Ny * Point1.Trans(2) + _ 
          Nz * Point1.Trans(3)) 

    ' If the denominator = 0, the ray is parallel 
    ' to the plane so there's no intersection. 
    denom = A * Vx + B * Vy + C * Vz 
    If denom = 0 Then 
        RayTraceable_FindT = -1
        Exit Function

 
< previous page page_603 next page >